package com.zdxk.msgPush.common.rocket.produce;

import com.zdxk.msgPush.common.config.RocketMqConfig;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum  RocketMqProducer {

    instance;

    private static Logger logger = LoggerFactory.getLogger(RocketMqProducer.class);

    private DefaultMQProducer producer;

    static {
        if("true".equals(RocketMqConfig.getConf("rocketMq.producer.enable"))){
            DefaultMQProducer producerTemp = new DefaultMQProducer(RocketMqConfig.getConf("rocketMq.producer.groupName"));
            producerTemp.setVipChannelEnabled(false);
            producerTemp.setNamesrvAddr(RocketMqConfig.getConf("rocketMq.nameServer.domain"));
            instance.producer = producerTemp;
            try {
                instance.producer.start();
            } catch (MQClientException e) {
                logger.error("rocketMq生产者启动失败",e);
            }
        }
    }

    public static DefaultMQProducer getProducer() {
        return instance.producer;
    }
}
